package com.ih.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ih.pojo.Order;
import com.ih.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @ClassName OrderController
 * @Description
 * @Author xiaozhang
 * @date 2023-05-06
 */
@Controller
public class OrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/getListOrder")
    public String listOrderd(Model model, @RequestParam(required = false,defaultValue = "1",value = "pageMum") Integer pageNum,@RequestParam(required = false,defaultValue = "10",value = "pageSize") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Order> pageInfo=orderService.listOrder(pageNum,pageSize);
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int size = pageInfo.getList().size();
        for (int i = 0; i < size; i++) {
            pageInfo.getList().get(i).setEndTime_1(dateFormat.format(pageInfo.getList().get(i).getEndTime()));
            pageInfo.getList().get(i).setStartTime_1(dateFormat.format(pageInfo.getList().get(i).getStartTime()));
        }
        model.addAttribute("pageInfo",pageInfo);

        System.out.println("pageInfo = " + pageInfo);
        return "orderList";
    }

}
